package cn.edu.hit.education.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import cn.edu.hit.education.dialog.SpecialtyDialog;
import cn.edu.hit.education.pojo.Specialty;
import cn.edu.hit.education.service.ISpecialtyService;
import cn.edu.hit.education.view.DepartmentExploreView;
import educationschedule.Activator;
import educationschedule.Application;

public class UpdateSpecialtyAction extends Action {
	ISpecialtyService specialtyService = (ISpecialtyService)Application.applicationContext.getBean("specialtyServiceImpl");
	private int specialtyId;
	private DepartmentExploreView viewPart;
	/**
	 * @wbp.parser.entryPoint
	 */
	public UpdateSpecialtyAction(DepartmentExploreView viewPart,int specialtyId){
		this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png"));
		this.setToolTipText("修改专业");
		this.setText("修改专业");
		this.viewPart = viewPart;
		this.specialtyId = specialtyId;
	}
	
	@Override
	public void run() {
		Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		SpecialtyDialog specialtyDialog = new SpecialtyDialog(parentShell);
		Specialty specialty = specialtyService.queryByPrimaryKey(specialtyId);
		specialtyDialog.setSpecialty(specialty);
		if(IDialogConstants.OK_ID == specialtyDialog.open()){
			int count = specialtyService.update(specialty);
			if(count > 0){
				viewPart.refreshUpdateData(specialty);
			}
		}
		super.run();
	}
}
